package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.core.annotation.Order;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    void insert(Orders order);
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);
    void update(Orders orders);
    @Select("select * from orders where user_id=#{userId}")
    List<Orders> orderListByUserId(long userId);
    @Select("select count(*) from orders where user_id=#{userId}")
    Integer OrderCount(Long userId);
    @Select("select * from orders where id=#{id}")
    Orders getOrderById(Long id);
    @Update("update orders set status=5 where id=#{id}")
    void cancelOrder(Long id);
    /**
     * 查询各种状态订单的数量
     */
    @Select("select count(*) from orders where status=2")
    Integer getoBeConfirmedCount();
    @Select("select count(*) from orders where status=3")
    Integer getconfirmed();
    @Select("select count(*) from orders where status=4")
    Integer getdeliveryInProgressCount();
    /**
     * 分页条件查询并按下单时间排序
     * @param ordersPageQueryDTO
     *
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);
    @Update("update orders set status=6 where id=#{id}")
    void usercancel(Long id);
    @Update("update orders set cancel_reason=#{cancelReason},status=5 where id=#{id}")
    void cancel(OrdersCancelDTO ordersCancelDTO);
    @Update("update orders set rejection_reason=#{rejectionReason},status=5 where id=#{id}")
    void reject(OrdersRejectionDTO ordersRejectionDTO);
    @Update("update orders set status=4 where id=#{id}")
    void delivery(Long id);
    @Update("update orders set status=5 where id=#{id}")
    void complete(Long id);
    @Select("select * from orders where status=#{status} and order_time<#{orderTime}")
    List<Orders> getByStatusAndOrdertimeLT(Integer status, LocalDateTime orderTime);
    Double sumByMap(Map map);
    Integer getCount(Map map);//这个属于用户接口
    //获得指定时间订单
    Integer getOrders(Map map);
    List<GoodsSalesDTO> getTop10Report(Map map);

}
